package com.hongxun.design.utils;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.model.LatLng;
import com.hongxun.design.MyApp;
import com.hongxun.design.R;
import com.hongxun.design.activitys.DotDesignActivity;
import com.hongxun.design.activitys.LogFillActivity;
import com.hongxun.design.activitys.ProjectMapActivity;
import com.hongxun.design.activitys.ProjectMapSecondActivity;
import com.hongxun.design.activitys.ProjectSelfCheckActivity;
import com.hongxun.design.activitys.SetPointInformationActivity;
import com.hongxun.design.bean.CreateDistanceBean;
import com.hongxun.design.bean.CreateProjectBean;
import com.hongxun.design.bean.PhotoEnvironmentalItemBean;
import com.hongxun.design.bean.PopWindowItemBean;
import com.hongxun.design.bean.SetPointInfItemBean;
import com.hongxun.design.bean.ShareIconBean;
import com.hongxun.design.bean.photopassbean.PhotoPassIconBean;
import com.hongxun.design.bean.photopassbean.SystemTypeBean;
import com.hongxun.design.jungong.dialog.CreateModelDialog;
import com.hongxun.design.mytools.IconSourse;
import com.hongxun.design.mytools.IntentToActivity;
import com.hongxun.design.mytools.MString;
import com.hongxun.design.mytools.MyLog;
import com.hongxun.design.mytools.ToastShow;
import com.hongxun.design.ui.pickerview.OptionsPopupWindow;
import com.hongxun.design.ui.pickerview.TimePopupWindow;
import com.hongxun.design.ui.titlepopupwindow.ActionItem;
import com.hongxun.design.ui.titlepopupwindow.BitTypeBean;
import com.hongxun.design.ui.titlepopupwindow.BitTypePopup;
import com.hongxun.design.ui.titlepopupwindow.ProjectMapPopup;
import com.hongxun.design.ui.titlepopupwindow.SharePop;
import com.hongxun.design.ui.titlepopupwindow.TitlePopup;
import com.hongxun.design.utils.httputil.HttpStringUtil;
import com.hongxun.design.utils.imageutil.UriUtil;
import com.umeng.socialize.bean.SHARE_MEDIA;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * Created by zerdoor_pc on 2016/4/28.
 */
public class PopwindowUtil {
    public static TitlePopup titlePopup;

    //首页pop
    public static void openPop(TextView add, final Activity context, List<PopWindowItemBean> title) {
        if (title == null) {
            ToastShow.showShort(context, "弹出框数据为空！");
            return;
        }
        //实例化标题栏弹窗
        titlePopup = new TitlePopup(context, WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT);
        int num = title.size();
        for (PopWindowItemBean bean : title) {
            titlePopup.addAction(new ActionItem(bean));
        }

        titlePopup.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                WindowManager.LayoutParams params = context.getWindow().getAttributes();
                params.alpha = 1f;
                context.getWindow().setAttributes(params);
                titlePopup.cleanAction();
                titlePopup = null;
            }
        });
        titlePopup.show(add);
        WindowManager.LayoutParams params = context.getWindow().getAttributes();
        params.alpha = 0.7f;
        context.getWindow().setAttributes(params);
    }

    //打开地址联动pop
    public static void popChoice(final Activity con, final TextView view, final CreateProjectBean bean) {
        final ArrayList<String> list = bean.getData();
        if (list == null) {
            WindowManager.LayoutParams params = con.getWindow().getAttributes();
            params.alpha = 1f;
            con.getWindow().setAttributes(params);
            return;
        }
        final ArrayList<String> listcode = bean.getDataValue();
        //选项选择器
        final OptionsPopupWindow pwOptions = new OptionsPopupWindow(con);
        //选项1
        //三级联动效果
        pwOptions.setPicker(list);
        pwOptions.setSelectOptions(0, 0, 0);
        pwOptions.setItemLength(10);
        //监听确定选择按钮
        pwOptions.setOnoptionsSelectListener(new OptionsPopupWindow.OnOptionsSelectListener() {

            @Override
            public void onOptionsSelect(int options1, int option2, int options3) {
                //返回的分别是三个级别的选中位置
                view.setText(list.get(options1));
                view.setTextColor(con.getResources().getColor(R.color.gray));
                bean.setValue(list.get(options1));
                bean.setValuecode(listcode.get(options1));

            }
        });
        pwOptions.showAtLocation(view, Gravity.BOTTOM, 0, 0);
        pwOptions.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                WindowManager.LayoutParams params = con.getWindow().getAttributes();
                params.alpha = 1f;
                con.getWindow().setAttributes(params);
            }
        });
    }

    public static void popChoice2(final Activity con, final TextView view,
                                  final SetPointInfItemBean bean, ArrayList<SystemTypeBean> data) {
        final ArrayList<String> list = new ArrayList<>();
        final ArrayList<String> list_code = new ArrayList<>();
        final List<LatLng> lngList = new ArrayList<>();
        for (SystemTypeBean systemTypeBean : data) {
            list.add(systemTypeBean.getTypename());
            list_code.add(systemTypeBean.getTypecode());
        }
        //选项选择器
        final OptionsPopupWindow pwOptions = new OptionsPopupWindow(con);
        //选项1
        //三级联动效果
        pwOptions.setPicker(list);
        pwOptions.setSelectOptions(0, 0, 0);
        pwOptions.setItemLength(50);
        //监听确定选择按钮
        pwOptions.setOnoptionsSelectListener(new OptionsPopupWindow.OnOptionsSelectListener() {

            @Override
            public void onOptionsSelect(int options1, int option2, int options3) {
                //返回的分别是三个级别的选中位置
                view.setText(list.get(options1));
                bean.setValue(list.get(options1));
                bean.setValueCode(list_code.get(options1));
                if (bean.getNameCode().equals(MString.is_common)) {
                    if (list.get(options1).equals(MString.YES_)) {//1
                        if (SetPointInformationActivity.ChoiceData == null ||
                                SetPointInformationActivity.ChoiceData.size() == 0) {
                            view.setText(list.get(1));
                            bean.setValue(list.get(1));
                            bean.setValueCode(list_code.get(1));
                        }
                        popChoice2(con, view, SetPointInformationActivity.ChoiceData);
                    } else {
                        try {
                            SetPointInformationActivity.setValue();
                        } catch (Exception e) {
                        }
                    }
                } else if (bean.getNameCode().equals(MString.before_exp)) {
                    if (list_code.get(options1).length() == 0) {
                        ((SetPointInformationActivity) con).cornerHandler.sendEmptyMessage(2);
                    } else {
                        ((SetPointInformationActivity) con).setBefore_exp_id(list.get(options1), list_code.get(options1));
                        LatLng latLng = ((SetPointInformationActivity) con).getLatLng();
                        if (MyApp.isOnLine) {
                            Message msg = new Message();
                            msg.what = 3;
                            msg.arg1 = options1;
                            ((SetPointInformationActivity) con).cornerHandler.sendMessage(msg);
                            MyApp.HTTP.getexpCorner(((SetPointInformationActivity) con).cornerHandler, HttpStringUtil.SUCCESSED, latLng, list_code.get(options1), SetPointInformationActivity.type);
                        } else {
                            ((SetPointInformationActivity) con).getPaizi();
                        }
                    }
                } else if (bean.getNameCode().equals(MString.voltage_grade)) {
                    MyApp.voltage_grade = list_code.get(options1);
                    try {
                        ((SetPointInformationActivity) con).setUpdateva();
                    } catch (Exception e) {
                    }
                    try {
                        ((DotDesignActivity) con).setUpdateva();
                    } catch (Exception e) {
                    }
                }
            }
        });
        pwOptions.showAtLocation(view, Gravity.BOTTOM, 0, 0);
        pwOptions.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                WindowManager.LayoutParams params = con.getWindow().getAttributes();
                params.alpha = 1f;
                con.getWindow().setAttributes(params);
                try {
                    SetPointInformationActivity.adapter.notifyDataSetChanged();
                } catch (Exception e) {
                }
                try {
                    DotDesignActivity.adapter.notifyDataSetChanged();
                } catch (Exception e) {
                }
                try {
                    ((SetPointInformationActivity) con).map_style.setVisibility(View.GONE);
                } catch (Exception e) {
                }
            }
        });
    }

    public static void popChoice2(final Activity con, final TextView view, final ArrayList<SystemTypeBean> data) {
        if (data == null || data.size() == 0) {
            return;
        }
        final ArrayList<String> list = new ArrayList<>();
        final ArrayList<String> list_code = new ArrayList<>();
        final ArrayList<String> list_lat = new ArrayList<>();
        final ArrayList<String> list_lng = new ArrayList<>();
        for (SystemTypeBean systemTypeBean : data) {
            list.add(systemTypeBean.getTypename());
            list_code.add(systemTypeBean.getTypecode());
            list_lat.add(systemTypeBean.code);
            list_lng.add(systemTypeBean.name);
        }
        //选项选择器
        final OptionsPopupWindow pwOptions = new OptionsPopupWindow(con);
        //选项1
        //三级联动效果
        pwOptions.setPicker(list);
        pwOptions.setSelectOptions(0, 0, 0);
        pwOptions.setItemLength(50);
        //监听确定选择按钮
        pwOptions.setOnoptionsSelectListener(new OptionsPopupWindow.OnOptionsSelectListener() {

            @Override
            public void onOptionsSelect(int options1, int option2, int options3) {
                //返回的分别是三个级别的选中位置
                String g_exp_id = "";
                LatLng latLng = null;
                try {
                    g_exp_id = list_code.get(options1);//选择的点的id
                    String lat = list_lat.get(options1);//选择的点的id
                    String lng = list_lng.get(options1);//选择的点的id
                    if (lat.length() == 0 || lng.length() == 0) return;
                    latLng = new LatLng(Double.parseDouble(lat), Double.parseDouble(lng));
                } catch (Exception e) {
                }
                try {
                    SetPointInformationActivity.setValue(latLng, g_exp_id);
                } catch (Exception e) {
                }
                try {
                    DotDesignActivity.setValue(latLng, g_exp_id);
                } catch (Exception e) {
                }
            }
        });
        pwOptions.showAtLocation(view, Gravity.BOTTOM, 0, 0);
        pwOptions.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                WindowManager.LayoutParams params = con.getWindow().getAttributes();
                params.alpha = 1f;
                con.getWindow().setAttributes(params);
                try {
                    SetPointInformationActivity.adapter.notifyDataSetChanged();
                } catch (Exception e) {
                }
                try {
                    ((SetPointInformationActivity) con).map_style.setVisibility(View.GONE);
                } catch (Exception e) {
                }
            }
        });
    }

    public static void popChoice_photo(final Activity con, final TextView view, final PhotoEnvironmentalItemBean bean) {
        final ArrayList<String> list = bean.getData();
        final ArrayList<String> dataValue = bean.getDataValue();
        //选项选择器
        final OptionsPopupWindow pwOptions = new OptionsPopupWindow(con);
        //选项1
        //三级联动效果
        pwOptions.setPicker(list);
        pwOptions.setSelectOptions(0, 0, 0);
        pwOptions.setItemLength(10);
        //监听确定选择按钮
        pwOptions.setOnoptionsSelectListener(new OptionsPopupWindow.OnOptionsSelectListener() {

            @Override
            public void onOptionsSelect(int options1, int option2, int options3) {
                //返回的分别是三个级别的选中位置
                view.setText(list.get(options1));
                bean.setValue(list.get(options1));
                bean.setValuecode(dataValue.get(options1));

            }
        });
        pwOptions.showAtLocation(view, Gravity.BOTTOM, 0, 0);
        pwOptions.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                WindowManager.LayoutParams params = con.getWindow().getAttributes();
                params.alpha = 1f;
                con.getWindow().setAttributes(params);
                try {
                    ((SetPointInformationActivity) con).map_style.setVisibility(View.GONE);
                } catch (Exception e) {
                }
            }
        });
    }

    public static void popChoice_PhotoDialog(final Activity con, final TextView view, final PhotoPassIconBean bean, View parent) {
        final ArrayList<SystemTypeBean> list = (ArrayList<SystemTypeBean>) bean.getData();
        final ArrayList<String> value = new ArrayList<>();
        final ArrayList<String> valueCode = new ArrayList<>();
        for (SystemTypeBean b : list) {
            valueCode.add(b.getTypecode());
            value.add(b.getTypename());
        }
        //选项选择器
        final OptionsPopupWindow pwOptions = new OptionsPopupWindow(MyApp.activity);
        //选项1
        //三级联动效果
        pwOptions.setPicker(value);
        //设置选择的三级单位
        //pwOptions.setLabels("省", "市", "区");
        //设置默认选中的三级项目
        pwOptions.setSelectOptions(0, 0, 0);
        pwOptions.setItemLength(10);
        //监听确定选择按钮
        pwOptions.setOnoptionsSelectListener(new OptionsPopupWindow.OnOptionsSelectListener() {

            @Override
            public void onOptionsSelect(int options1, int option2, int options3) {
                //返回的分别是三个级别的选中位置
                view.setText(value.get(options1));
                bean.setValue(value.get(options1));
                bean.setValuecode(valueCode.get(options1));

            }
        });

        pwOptions.showAtLocation(parent, Gravity.BOTTOM, 0, 0);
        pwOptions.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                WindowManager.LayoutParams params = con.getWindow().getAttributes();
                params.alpha = 1f;
                con.getWindow().setAttributes(params);

            }
        });
    }

    /**
     * 项目地图跳转*
     */
    public static void popChoiceToActivity(final Activity con, MapView view,
                                           List<SystemTypeBean> data, final String json) {
        final ArrayList<String> list = new ArrayList<>();
        final ArrayList<String> list_code = new ArrayList<>();
        final ArrayList<String> list_code_id = new ArrayList<>();
        for (SystemTypeBean systemTypeBean : data) {
            list.add(systemTypeBean.getTypename());
            list_code.add(systemTypeBean.getTypecode());
            list_code_id.add(systemTypeBean.code);
        }

        //选项选择器
        final OptionsPopupWindow pwOptions = new OptionsPopupWindow(con);
        //选项1
        //三级联动效果
        pwOptions.setPicker(list);
        pwOptions.setSelectOptions(0, 0, 0);
        pwOptions.setItemLength(10);
        //监听确定选择按钮
        pwOptions.setOnoptionsSelectListener(new OptionsPopupWindow.OnOptionsSelectListener() {

            @Override
            public void onOptionsSelect(int options1, int option2, int options3) {
                //返回的分别是三个级别的选中位置
//                view.setText(list.get(options1));
                MyLog.L(MString.SUCCESSED + "点击");
                Bundle bundle = new Bundle();
                bundle.putString(MString.stage_id, list_code.get(options1));
                bundle.putString(MString.stage, list_code_id.get(options1));
                bundle.putString(MString.PATH, json);
                bundle.putString(MString.TYPE, MString.MAP);
                IntentToActivity.intent(con, ProjectMapActivity.class, bundle);

            }
        });
        pwOptions.showAtLocation(view, Gravity.BOTTOM, 0, 0);
        pwOptions.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                WindowManager.LayoutParams params = con.getWindow().getAttributes();
                params.alpha = 1f;
                con.getWindow().setAttributes(params);

            }
        });
    }


    //点位类型pop
    public static BitTypePopup bittypepopup;

    @SuppressLint("NewApi")
    public static void openBitPop(final View add, final View other, final Activity context) {

        //实例化标题栏弹窗
        if (bittypepopup == null) {
            bittypepopup = new BitTypePopup(context, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
            bittypepopup.addAction(new BitTypeBean("新", "新建点", "11"));
//            bittypepopup.addAction(new BitTypeBean("拆", "拆旧点", "12"));
        }
        bittypepopup.setItemOnClickListener(new BitTypePopup.OnItemOnClickListener() {
            @Override
            public void onItemClick(BitTypeBean item, int position) {
                TextView bittype_icon = (TextView) add.findViewById(R.id.bittype_icon);
                TextView bittype_title = (TextView) add.findViewById(R.id.bittype_title);
                bittype_icon.setText(item.getType());
                bittype_title.setText(item.getName());
                try {
                    if (MyApp.currExploration.getLat().length() != 0 && MyApp.currExploration.getLng().length() != 0) {
                        if (bittype_icon.getText().toString().equals("新")) {
                            MyApp.currExploration.setPoint_type("11");
                        } else {
                            MyApp.currExploration.setPoint_type("12");
                        }
                    }

                } catch (Exception e) {
                    ((ProjectSelfCheckActivity) context).type = item.code;
                }


            }
        });
        bittypepopup.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                other.setAlpha(1.0f);
                add.setAlpha(1.0f);


            }
        });
        bittypepopup.show(add);
        other.setAlpha(0.7f);
        add.setAlpha(0.7f);
    }

    //项目地图台区pop
    public static ProjectMapPopup projectmappopup;

    @SuppressLint("NewApi")
    public static void openProjectMapPop(final View add, final View other, final Activity context, List<BitTypeBean> data, final String name) {
        //实例化标题栏弹窗
        if (projectmappopup == null) {
            projectmappopup = new ProjectMapPopup(context, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
        }
        projectmappopup.cleanAction();

        for (BitTypeBean b : data) {
            projectmappopup.addAction(b);
        }
        projectmappopup.setItemOnClickListener(new ProjectMapPopup.OnItemOnClickListener() {
            @Override
            public void onItemClick(BitTypeBean item, int position) {
                TextView bittype_title = (TextView) add.findViewById(R.id.projectmap_pop_title);
                bittype_title.setText(item.getName());
                //跳转到activity
                Bundle bundle = new Bundle();
                bundle.putString(MString.number, item.code);
                // bundle.putString(MString.CODE, item.code);
                bundle.putString(MString.TYPE, item.getType());
                bundle.putString(MString.CODE, item.code2);
                bundle.putString(MString.name, name);
                bundle.putString(MString.explor_name, item.getName());
                IntentToActivity.intent(context, ProjectMapSecondActivity.class, bundle);
                //item.getType();
            }
        });
        projectmappopup.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                add.setAlpha(1.0f);
            }
        });
        projectmappopup.show(add);
        add.setAlpha(0.7f);
    }

    static PopupWindow window;

    public static void openSetPointPopBottom(View v, final Activity activity, final Handler handler) {
        if (window != null && window.isShowing()) return;
        View layoutMenu = LayoutInflater.from(activity).inflate(R.layout.pop_tobottom, null);
        window = new PopupWindow(layoutMenu, DensityUtil.dip2px(activity, 224), DensityUtil.dip2px(activity, 100));
        //让弹出框获取焦点（为了让菜单里面的按钮可以点击）
        window.setFocusable(true);
        //触摸弹出框外面位置，自动dismiss
        window.setBackgroundDrawable(new ColorDrawable());//这句很关键！
        window.setOutsideTouchable(true);
        //显示PopupWindow
        // window.showAsDropDown(v);//下方弹出
        int[] location = new int[2];
        v.getLocationOnScreen(location);
        window.showAtLocation(v, Gravity.NO_GRAVITY, location[0] - 40, location[1] - window.getHeight());//上方弹出
//        window.showAtLocation(v, Gravity.NO_GRAVITY, location[0]-window.getWidth(), location[1]);//左
//        window.showAtLocation(v, Gravity.NO_GRAVITY, location[0]+v.getWidth(), location[1]);//右
        WindowManager.LayoutParams params = activity.getWindow().getAttributes();
        params.alpha = 0.7f;
        activity.getWindow().setAttributes(params);
        ((SetPointInformationActivity) activity).map_style.setVisibility(View.VISIBLE);

        //设置menu里面按钮点击监听
        LinearLayout button1 = (LinearLayout) layoutMenu.findViewById(R.id.button1);//复核
        LinearLayout button4 = (LinearLayout) layoutMenu.findViewById(R.id.button4);//拍照

        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                ListenerSet.getDesignClickListener(activity);
                handler.sendEmptyMessage(1);
                window.dismiss();
                window = null;
            }
        });

        button4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                IntentToActivity.intent(activity, PhotoGraphActivity.class);
                handler.sendEmptyMessage(2);
                window.dismiss();
                window = null;

            }
        });
        window.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                WindowManager.LayoutParams params = activity.getWindow().getAttributes();
                params.alpha = 1f;
                activity.getWindow().setAttributes(params);
                ((SetPointInformationActivity) activity).map_style.setVisibility(View.GONE);
            }
        });
    }


    /**
     * 时间选择器*
     */
    public static void timeChoice(Activity activity, final Object msg, View view, final Handler handler, final int i) {
        //时间选择器
        TimePopupWindow pwTime = new TimePopupWindow(activity, TimePopupWindow.Type.YEAR_MONTH_DAY);
        Date mdate = new Date();
        final CreateDistanceBean bean = (CreateDistanceBean) msg;
        pwTime.setTime(mdate);
        Calendar c = Calendar.getInstance();
        pwTime.setRange(1950, c.get(Calendar.YEAR));
        //时间选择后回调
        pwTime.setOnTimeSelectListener(new TimePopupWindow.OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date) {
                bean.setValue(TimeUtil.time(date) + "");
                handler.sendEmptyMessage(i);
            }
        });
        pwTime.showAtLocation(view, Gravity.BOTTOM, 0, 0, new Date());
    }

    public static Date currdate = null;

    public static void openTimePicker(int start, final TextView tvTime, final Activity con, final String tag) {
        //时间选择器
        TimePopupWindow pwTime = new TimePopupWindow(con, TimePopupWindow.Type.YEAR_MONTH_DAY);
        Date mdate = new Date();
        pwTime.setTime(mdate);
        Calendar c = Calendar.getInstance();
        pwTime.setRange(start, c.get(Calendar.YEAR));
        //时间选择后回调
        pwTime.setOnTimeSelectListener(new TimePopupWindow.OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date) {
                String time = getTime(date);
                tvTime.setText(time);
                try {
                    if (tag.equals(MString.startDate)) {
                        ((LogFillActivity) con).startDate = time;
                        ((LogFillActivity) con).endDate = "";
                        ((LogFillActivity) con).logfill_etime.setText("-");
                        currdate = date;
                    } else if (tag.equals(MString.endDate)) {

                        if (date.getTime() >= currdate.getTime()) {
                            ((LogFillActivity) con).endDate = time;
                        } else {
                            tvTime.setText("-");
                            ((LogFillActivity) con).endDate = "";
                            ToastShow.showShort(con, "结束时间不能早于开始时间！");
                        }

                    }
                } catch (Exception e) {
                }
            }
        });
        pwTime.showAtLocation(tvTime, Gravity.BOTTOM, 0, 0, new Date());
    }

    private static String getTime(Date date) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        return format.format(date);
    }

    public static void sharePop(final Activity context, final View add, String title, String thumb, String url, String intro) {
        SharePop sharePop = new SharePop(context, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
        sharePop.cleanAction();
        sharePop.addAction(new ShareIconBean(IconSourse.weixin + "", "微信好友", SHARE_MEDIA.WEIXIN, R.drawable.circular_share_green_all));
        sharePop.addAction(new ShareIconBean(IconSourse.weixincicle + "", "微信朋友圈", SHARE_MEDIA.WEIXIN_CIRCLE, R.drawable.circular_share_green_all));
        sharePop.addAction(new ShareIconBean(IconSourse.QQ + "", "QQ好友", SHARE_MEDIA.QQ, R.drawable.circular_blue_all));
        // MyLog.L(MString.SUCCESSED+" url="+(new Uri.Builder()).scheme("res").path(String.valueOf(R.mipmap.zhanweixiangmu)).build());
        sharePop.setShare(title, UriUtil.getString(thumb), url, intro);
        sharePop.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                WindowManager.LayoutParams params = context.getWindow().getAttributes();
                params.alpha = 1f;
                context.getWindow().setAttributes(params);
            }
        });
        sharePop.show(add);
        WindowManager.LayoutParams params = context.getWindow().getAttributes();
        params.alpha = 0.8f;
        context.getWindow().setAttributes(params);
    }


    public static void popChoice_JG(final Activity con, final TextView view, final ArrayList<String> list) {
        OptionsPopupWindow pwOptions = new OptionsPopupWindow(con);
        pwOptions.setPicker(list);
        pwOptions.setSelectOptions(0, 0, 0);
        pwOptions.setItemLength(10);
        pwOptions.setOnoptionsSelectListener(new OptionsPopupWindow.OnOptionsSelectListener() {

            @Override
            public void onOptionsSelect(int options1, int option2, int options3) {
                view.setText(list.get(options1));
                view.setTextColor(con.getResources().getColor(R.color.gray));
            }
        });
        if (list.contains("电缆(沿墙)"))
            pwOptions.showAtLocation(CreateModelDialog.view, Gravity.TOP, 0, 0);
        else
            pwOptions.showAtLocation(view, Gravity.BOTTOM, 0, 0);

        pwOptions.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                WindowManager.LayoutParams params = con.getWindow().getAttributes();
                params.alpha = 1f;
                con.getWindow().setAttributes(params);
            }
        });
    }

    public static void popChoice_JG_file(final Activity con, final View view,
                                         final ArrayList<String> list, final Handler handler, final int index) {
        OptionsPopupWindow pwOptions = new OptionsPopupWindow(con);
        pwOptions.setPicker(list);
        pwOptions.setSelectOptions(0, 0, 0);
        if (index == 3)
            pwOptions.setItemLength(10);
        else
            pwOptions.setItemLength(100);

        pwOptions.setOnoptionsSelectListener(new OptionsPopupWindow.OnOptionsSelectListener() {

            @Override
            public void onOptionsSelect(int options1, int option2, int options3) {
                Message msg = new Message();
                msg.obj = options1;
                msg.what = index;
                handler.sendMessage(msg);
            }
        });
        pwOptions.showAtLocation(view, Gravity.BOTTOM, 0, 0);
        pwOptions.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                WindowManager.LayoutParams params = con.getWindow().getAttributes();
                params.alpha = 1f;
                con.getWindow().setAttributes(params);
            }
        });
    }

    /**
     * 下拉数据选择器
     * 0Activity
     * 1ArrayList<String> list
     * 2View
     * 3handler
     * 4index
     */
    public static void dropdownpop(Object... obj) {
        final Activity activity = (Activity) obj[0];
        ArrayList<String> list = (ArrayList<String>) obj[1];
        View view = (View) obj[2];
        final Handler handler = (Handler) obj[3];
        final int index = (int) obj[4];

        OptionsPopupWindow pwOptions = new OptionsPopupWindow(activity);
        pwOptions.setPicker(list);
        pwOptions.setSelectOptions(0, 0, 0);
        pwOptions.setItemLength(10);
        pwOptions.showAtLocation(view, Gravity.BOTTOM, 0, 0);
//        pwOptions.showAsDropDown(view);
        pwOptions.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                WindowManager.LayoutParams params = activity.getWindow().getAttributes();
                params.alpha = 1f;
                activity.getWindow().setAttributes(params);
            }
        });
        pwOptions.setOnoptionsSelectListener(new OptionsPopupWindow.OnOptionsSelectListener() {

            @Override
            public void onOptionsSelect(int options1, int option2, int options3) {
                Message msg = new Message();
                msg.arg1 = options1;
                msg.what = index;
                handler.sendMessage(msg);
            }
        });
    }
}
